﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using Alos.Common;
using Alos.Entity;
using System.Threading.Tasks;
using Alos.IService;

namespace Alos.LanClass.Api
{
    /// <summary>
    /// 学生课堂问答表
    /// </summary>
    public class RePutQuestionController : ApiController
    {
       IRePutQuestionService RePutQuestionService;
        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="_RePutQuestionService"></param>
       public RePutQuestionController(IRePutQuestionService _RePutQuestionService)
        {
            RePutQuestionService = _RePutQuestionService;         
        }
       /// <summary>
       ///添加学生课堂问答
       /// </summary>
       /// <param name="RePutQuestion"></param>
       /// <returns></returns>
       [HttpPost]
       [Route("api/RePutQuestion/CreateRePutQuestion")]
       public JsonRtn<dynamic> CreateRePutQuestion([FromBody]RePutQuestion RePutQuestion)
       {
           var jsRtn = new JsonRtn<dynamic>();
           RePutQuestion.ID = System.Guid.NewGuid();
           jsRtn.data = RePutQuestionService.CreateRePutQuestion(RePutQuestion) ? RePutQuestion.ID.ToString() : "添加失败";
           return jsRtn;
       }
       /// <summary>
       ///修改学生课堂问答
       /// </summary>
       /// <param name="Id"></param>
       /// <returns></returns>
       [HttpGet]
       [Route("api/RePutQuestion/UpdateRePutQuestion")]
       public JsonRtn<dynamic> UpdateRePutQuestion(int id)
       {
           var jsRtn = new JsonRtn<dynamic>();
           jsRtn.message = RePutQuestionService.UpdateRePutQuestion(id)? "true" : "false";
           return jsRtn;
       }
       /// <summary>
       ///根据老师ID和备课ID获取学生课堂问答
       /// </summary>
       /// <param name="data">备课ID</param>
       /// <returns></returns>
       [HttpGet]
       [Route("api/RePutQuestion/getRePutQuestion")]
       public async Task<JsonRtn<dynamic>> getRePutQuestion(int LessionID)
       {
           var jsRtn = new JsonRtn<dynamic>();
           jsRtn.data = await Task.Factory.StartNew(id =>
           {
               return RePutQuestionService.getRePutQuestion((int)id, LessionID);
           }, Common.Current.User.id);
           return jsRtn;
       }
    }
}
